<script setup lang="ts">
import {useTokenStore} from '@/stores/token'
import { reactive, ref } from 'vue'
import {useRouter,useRoute} from 'vue-router'

const formParam = reactive({
    name: '',
    region: ''
})

const router = useRouter()
const route = useRoute()

function onSubmit(){

    // 模拟登录成功，设置token
    const tokenUtil = useTokenStore();
    tokenUtil.setToken('abcdedflg132456');

  
    // 判断是直接登录还是重定向
    if(route.query.redirectTo){
        router.push({
            path: <string>route.query.redirectTo,
            query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : ''
        })
    }else{
        router.push('/home')
    }
    

}

</script>

<template>
    <div class="login flexlayout_center">
        <el-form
            :module="formParam"
            label-width="100px"
            style="max-width: 460px">
            <el-form-item label="姓名">
                <el-input v-model="formParam.name" />
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="formParam.region" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<style scoped>
.login {
    width: 100vw;
    height: 30vh;
    margin-top: 35vh;
    overflow: hidden;
    background-color: rgb(51, 50, 50);
    
}
</style>
